package com.hanrui.android.fragment.message.audit.week;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.ProEleWeeklyMainDetailBean;
import com.hanrui.android.net.contract.message.audit.week.ProEleWeeklyMainDetailContract;
import com.hanrui.android.net.presenter.message.audit.week.ProEleWeeklyMainDetailPresenter;

import butterknife.BindView;

/**
 * 周报基本信息
 *
 */

public class ProEleWeeklyMainDetailFragment extends BaseFragment<ProEleWeeklyMainDetailPresenter> implements ProEleWeeklyMainDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.page_num)
    TextView pageNum;
    @BindView(R.id.ll_addview)
    LinearLayout lladdview;
    @BindView(R.id.invite_remark)
    TextView inviteRemark;

    String taskId,procInsId,bizId;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_proeleweeklymaindetail;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.proEleWeeklyMainBizDetail(getActivity(),taskId,procInsId,bizId);

    }



    public static ProEleWeeklyMainDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        ProEleWeeklyMainDetailFragment fragment = new ProEleWeeklyMainDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void proEleWeeklyMainBizDetail(final ProEleWeeklyMainDetailBean data) {

        if (null != data) {

            mainTitle.setText(data.getDetail().getTitle()+"审批");
            name.setText(data.getDetail().getTitle());
            thingTitle.setText(data.getDetail().getYearMonth());
            time.setText(data.getDetail().getWeekly());
            pageNum.setText(data.getDetail().getExpirationDate());
            inviteRemark.setText(data.getDetail().getNotify());


            if (null != data.getDetail().getProBusWeeklyReport() && data.getDetail().getProBusWeeklyReport().size() > 0) {

                lladdview.setVisibility(View.VISIBLE);

                for (int i = 0; i < data.getDetail().getProBusWeeklyReport().size(); i++) {

                    addViewItem(data.getDetail().getProBusWeeklyReport().get(i));
                }


            		}

        }

    }


    //添加ViewItem
    private void addViewItem(final ProEleWeeklyMainDetailBean.DetailBean.ProBusWeeklyReportBean bean) {
        View hotelEvaluateView = View.inflate(getActivity(), R.layout.item_weekly, null);
        TextView bidName = hotelEvaluateView.findViewById(R.id.bid_name);
        TextView bidUser = hotelEvaluateView.findViewById(R.id.bid_user);
        TextView bidPhone = hotelEvaluateView.findViewById(R.id.bid_phone);
        TextView bidTime = hotelEvaluateView.findViewById(R.id.bid_time);
        TextView bidBuildname = hotelEvaluateView.findViewById(R.id.bid_buildname);
        TextView bidBuildphone = hotelEvaluateView.findViewById(R.id.bid_buildphone);
        TextView bidPrice = hotelEvaluateView.findViewById(R.id.bid_price);
        LinearLayout enclosureLl = hotelEvaluateView.findViewById(R.id.enclosure_ll);
        ImageView enclosure = hotelEvaluateView.findViewById(R.id.enclosure);
        TextView enclosureNum = hotelEvaluateView.findViewById(R.id.enclosure_num);


        bidName.setText(bean.getProId());
        bidUser.setText(bean.getScheduleState());
        bidPhone.setText(bean.getProjectState());
        bidTime.setText(bean.getProjectInvestment());
        bidBuildname.setText(bean.getProgress());
        bidBuildphone.setText(bean.getTotalInvestment());
        bidPrice.setText(bean.getQuestion());


        if (null != bean.getFiles() && bean.getFiles().size() > 0) {

            enclosureLl.setVisibility(View.VISIBLE);
            enclosureNum.setText("["+bean.getFiles().size()+"]");
            enclosure.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    MyDownLoadActivity.start(getActivity(),bean.getFiles());

                }
            });

        		}

        lladdview.addView(hotelEvaluateView);
    }

}
